local skel = fk.CreateSkill{
  name = "tea__benhan",
  dynamic_desc = function (self, player)
    if player:getMark("tea__benhan_times") > 0 then
      return "tea__benhan_update:" .. (player:getMark("tea__benhan_times") + 1)
    end
  end,
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__benhan"] = "奔汉",
  [":tea__benhan"] = "每回合限 1 次，你的每个阶段结束时，你可以将手牌数调整至当前阶段数，若你手牌数：不变，本技能限制次数+1；减少，你出牌阶段使用【杀】额定次数视为本技能限制次数。",
  [":tea__benhan_update"] = "每回合限 {1} 次，你的每个阶段结束时，你可以将手牌数调整至当前阶段数，若你手牌数：不变，本技能限制次数+1；减少，你出牌阶段使用【杀】额定次数视为本技能限制次数。",
  ["#tea__benhan-invoke"] = "奔汉：现在是%arg2，你可以将手牌数调整为%arg",
  ["#tea__benhan-discard"] = "奔汉：你需将手牌弃至当前阶段数，需要弃置 %arg 张",
}
---@type TrigSkelSpec<PhaseFunc>
local benhan = {
  mute = true,
  times = function (self, player)
    return player:getMark("tea__benhan_times") + 1 - player:usedSkillTimes(skel.name)
  end,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player:usedSkillTimes(skel.name) < player:getMark("tea__benhan_times") + 1
  end,
  on_cost = function (self, event, target, player, data)
    if player.phase == 1 then return end
    local phases = { "", "phase_start", "phase_judge", "phase_draw", "phase_play", "phase_discard", "phase_finish" }
    return player.room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#tea__benhan-invoke:::" .. player.phase - 1 .. ":" .. phases[player.phase]
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(skel.name, player.phase - 1)
    room:notifySkillInvoked(player, skel.name, "special")
    if #player:getCardIds("h") == player.phase - 1 then
      room:addPlayerMark(player, "tea__benhan_times", 1)
    elseif #player:getCardIds("h") < player.phase - 1 then
      player:drawCards(player.phase - 1 - #player:getCardIds("h"), skel.name)
    else
      local num = #player:getCardIds("h") - player.phase + 1
      room:askToDiscard(player, {
        min_num = num,
        max_num = num,
        skill_name = skel.name,
        cancelable = false,
        prompt = "#tea__benhan-discard:::" .. num
      })
      if not player.dead then
        room:setPlayerMark(player, MarkEnum.SlashResidue, player:getMark("tea__benhan_times"))
      end
    end
  end
}
skel:addEffect(fk.EventPhaseEnd, benhan)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel